<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload=function(){
            //1.获取画布
            var canvas=document.getElementById("canvas");
            //2.获取画笔
            var cx=canvas.getContext("2d");
            //3.设置画笔样式
            cx.fillStyle="red";
            cx.strokeStyle="black";
            //4.绘制图形
            
            //绘制正方形
            // cx.fillRect(0,0,300,300);
            //绘制五角星
            cx.lineWidth=2;
            cx.beginPath();
            cx.moveTo(0,200);
            cx.lineTo(250,200);
            cx.lineTo(40,50);
            cx.lineTo(130,290);
            cx.lineTo(200,50);
            cx.lineTo(0,200);
            cx.closePath();
            cx.stroke();
            cx.globalCompositeOperation='destination-over';
            cx.fill();
           
            







        }
    </script>
</head>
<body>
    <canvas id="canvas" width="400px" height="400px" style="background-color: #ccc;"></canvas>
</body>
</html>